Release 10.1A: OpenEdge Data Management:
SQL Development
Referential constraints
Relational databases often contain tables that have identical columns. To maintain referential integrity, the data in the columns must remain consistent. Referential constraints ensure this integrity.
In Example 5–20, the value in the
item_nocolumn of thesupplier_itemtable depends on the value in theitem_nocolumn of theitemtable. Theitem_nocolumn of thesupplier_itemtable references theitem_nocolumn of theitemtable. Theitem_nocolumn is a foreign key in thesupplier_itemtable.
Foreign key constraint
A foreign key is a column that references a primary key of another table. The foreign key value either is
NULLor exists as the primary key value. The table that contains the foreign key is called the referencing table. The table that contains the primary key is called the referenced table.During
INSERTorUPDATEoperations on a table containing a foreign key, the database checks to determine if the foreign key value matches a corresponding primary key value. If it does not match, the operation returns an error.During
UPDATEorDELETEoperations on a table containing a primary or candidate key, if the values to be deleted or updated match the foreign key of the referencing table, the operation returns an error. A value corresponding to a primary or candidate key cannot be updated or deleted if there are references to it.When you want to drop a table containing a primary or candidate key, the database checks to see if the table has any references to it. If there are tables containing foreign keys that reference the primary or candidate keys of the table you want to drop, the operation returns an error.
In Example 5–21,
item_nois the foreign key referencing the item table, and the foreign key is specified at the column level.
If a foreign key references a candidate key, you must name the referenced column in a column list. If a foreign key references a primary key, the column list is optional.
Example 5–22 illustrates both conditions. In the example,
invoice.item_noreferences the primary key of theitemtable. Theinvoice.partnumcolumn referencesparts.part_no. Sinceparts.part_nois a primary key, the parts (part_no) column list reference ininvoice.part_nois optional.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |